# -*- coding: UTF-8 -*-
"""
@Filename:exerc3.py
@author:Cora
@time:2025-03-21
"""

import random

def generate_lottery_numbers():
    return random.sample(range(1, 34), 8)

def check_winning(target_numbers, user_numbers):
    correct_count = sum(1 for num in user_numbers if num in target_numbers)
    if correct_count == 8:
        return "一等奖"
    elif correct_count == 7:
        return "二等奖"
    elif correct_count == 6:
        return "三等奖"
    elif correct_count == 5:
        return "四等奖"
    else:
        return "未中奖"

# 生成特定的中奖号码
target_numbers = generate_lottery_numbers()
print("系统生成的中奖号码为:", target_numbers)

# 用户输入
user_input = input("请输入8个1-33之间的整数（用空格分隔）：")
user_numbers = list(map(int, user_input.split()))

# 检查用户是否中奖
result = check_winning(target_numbers, user_numbers)
print(f"您的结果是: {result}")

# 模拟随机购买10000注彩票
winning_counts = {
    "一等奖": 0,
    "二等奖": 0,
    "三等奖": 0,
    "四等奖": 0,
    "未中奖": 0
}

for _ in range(10000):
    user_numbers = generate_lottery_numbers()
    result = check_winning(target_numbers, user_numbers)
    winning_counts[result] += 1

# 打印中奖概率
total_tickets = 10000
print("\n模拟10000注彩票对特定号码的中奖概率：")
for level, count in winning_counts.items():
    probability = (count / total_tickets) * 100
    print(f"{level}概率: {probability:.2f}%")
